package cn.sdormitory.controller.api;

import cn.sdormitory.basedata.service.BStudentService;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.smartclass.service.ClassAttenceService;
import cn.sdormitory.smartdor.service.SdAttenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author: lx
 * @date: 2023/7/1 9:51
 * @description: 获取物联网系统考勤数据
 */
@RestController
@RequestMapping("/faceGate")
public class FaceGateController {

    @Autowired
    SdAttenceService sdAttenceService;

    @Autowired
    ClassAttenceService classAttenceService;

    @Autowired
    BStudentService bStudentService;

    @PostMapping(value = "/receiveSdAttendanceRecords",produces = "application/json;charset=UTF-8")
    public CommonResult receiveSdAttendanceRecords(@RequestBody List<Map<String,String>> records){
        try{
            boolean flag = sdAttenceService.receiveSdAttendanceRecords(records);
            return CommonResult.success("成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return CommonResult.failed("失败");
    }

    @PostMapping(value = "/receiveClsAttendanceRecords",produces = "application/json;charset=UTF-8")
    public CommonResult receiveClsAttendanceRecords(@RequestBody List<Map<String,String>> records){
        try{
            boolean flag = classAttenceService.receiveClsAttendanceRecords(records);
            return CommonResult.success("成功");
        }catch (Exception e){
            e.printStackTrace();
        }
        return CommonResult.failed("失败");
    }

    @PostMapping(value = "/syncStuPhoto",produces = "application/json;charset=UTF-8")
    public CommonResult syncStuPhoto(@RequestBody List<Map<String,String>> data){
        int num = bStudentService.syncStuPhoto(data);
        if(num > 0){
            return CommonResult.success("成功");
        }else {
            return CommonResult.failed("失败");
        }
    }
}
